//
//  ByCellIndexHealth.m
//  jinpuyiyuan_ios
//
//  Created by mc on 2017/12/5.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByCellIndexHealth.h"
@implementation ByCellIndexHealth
{
    UIView      *_line;
    UILabel     *_titleLabel;
    UIButton    *_likeButton;
    UILabel     *_likeCountLabel;
    UIImageView *_img;
}

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellIndexHealth";
    ByCellIndexHealth *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        [self createViews];
    }
    return self;
}

- (void)createViews{
    // line
    _line = [[UIView alloc] init];
    [self addSubview:_line];
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 1));
    }];
    _line.backgroundColor = [UIColor colorWithWhite:0.90 alpha:1];
    
    // img (70 : 50)
    _img = [[UIImageView alloc] init];
    [self addSubview:_img];
    [_img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.top.equalTo(@(5));
        make.size.mas_equalTo(CGSizeMake(70, 50));
    }];
    
    // title
    _titleLabel = [[UILabel alloc] init];
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(@(10));
        make.right.equalTo(_img.mas_left).offset(-10);
        make.height.equalTo(@(15));
    }];
    _titleLabel.font = FONT(14);
    
    // 点赞
    _likeButton = [[UIButton alloc] init];
    [self addSubview:_likeButton];
    [_likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    [_likeButton setImage:[UIImage imageNamed:@"Index_like"] forState:UIControlStateNormal];
    
    // 点赞数
    _likeCountLabel = [[UILabel alloc] init];
    [self addSubview:_likeCountLabel];
    [_likeCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_likeButton.mas_right).offset(5);
        make.top.equalTo(_likeButton.mas_top);
        make.right.equalTo(_img.mas_left).offset(-10);
        make.height.equalTo(@(15));
    }];
    _likeCountLabel.font = FONT(14);
    _likeCountLabel.textColor = [UIColor lightGrayColor];
}

- (void)setModel:(ByModelIndexHealth *)model{
    _model = model;
    
    // 测试数据
    _titleLabel.text = @"疏经络，补气血，冬天喝他正当时！！！！";
    _likeCountLabel.text = @"9989";
    _img.backgroundColor = BY_THEME_COLOR;
    if (_model.type_from.integerValue == 1) {
        _line.hidden = YES;
    }else{
        _line.hidden = NO;
    }
}



@end
